<?php
/**
 * User: hjd-yao
 * Date: 2019/5/6
 * Time: 18:17
 */

namespace App\Http\Controllers\Backend;


use App\Helpers\SelfResponse;
use App\Http\Controllers\BackendController;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Cache;
use Illuminate\Support\Facades\DB;

class SystemController extends BackendController
{
    /**
     * @title 清除缓存
     * @return JsonResponse|\Illuminate\Http\RedirectResponse
     */
    public function clearCache()
    {
        Cache::flush();
        return SelfResponse::success('缓存清除成功');
    }

    /**
     * @title 初始化数据
     * @param Request $request
     * @return JsonResponse|RedirectResponse
     */
    public function initData(Request $request)
    {

        $init_data = $request->post('init_data');

        if(in_array('user',$init_data)){
            $this->initUser();
        }

        if(in_array('rg',$init_data)){
            $this->initRg();
        }

        return SelfResponse::success('初始化成功');
    }

    private function initUser()
    {
        DB::table('users_base')->truncate();
        DB::table('users_auth')->truncate();
        DB::table('users_info')->truncate();
        DB::table('users_wallet')->truncate();
        DB::table('users_login_logs')->truncate();
        DB::table('user_sign_record')->truncate();
        DB::table('user_achievement')->truncate();
        DB::table('user_wd')->truncate();

        DB::table('upgrade')->truncate();
        DB::table('upgrade_info')->truncate();

        DB::table('recharge_record')->truncate();

        DB::table('tf_record')->truncate();

        DB::table('cms_notice_user')->truncate();

        DB::table('cms_message')->truncate();

        DB::table('shop_order')->truncate();
        DB::table('shop_order_goods')->truncate();
        DB::table('shop_goods_agent')->truncate();
        DB::table('shop_user_address')->truncate();
        DB::table('shop_cart')->truncate();
        DB::table('shop_order_goods_evaluate')->truncate();
        DB::table('shop_user_coupon')->truncate();

        DB::table('shop_stats')->truncate();

        DB::table('account_flow')->truncate();
        DB::table('account_correct')->truncate();
        DB::table('bonus_record')->truncate();
        DB::table('bonus_count')->truncate();
        DB::table('bonus_pools')->truncate();

        DB::table('logs_home')->truncate();

        DB::table('plat_finance')->truncate();

        DB::table('order_payment')->truncate();

        DB::table('logs_admin')->truncate();

        DB::table('logs_store')->truncate();

        DB::table('manage_admins_log')->truncate();

    }

    private function initRg()
    {
        DB::table('recharge_record')->truncate();
    }
}